package cumt.kydd.authoringplatform.service;

import cumt.kydd.authoringplatform.bean.History;
import cumt.kydd.authoringplatform.mapper.HistoryMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import static cumt.kydd.authoringplatform.service.UserService.LoginInUser;

@Service
public class SendHistoryService {
    @Resource
    private HistoryMapper historyMapper;

    public List<Integer> getUsersHistoryID()
    {
        List<Integer> result = new LinkedList<>();
        result = historyMapper.selectHistoryIDByNameAndIsDelete(LoginInUser.getName());

        return result;
    }

    public List<Integer> getUsersHistoryTrashID()
    {
        List<Integer> result = new LinkedList<>();
        result = historyMapper.selectHistoryIDByNameAndIsDeleteYet(LoginInUser.getName());

        return result;
    }

    public List<Integer> getUsersHistoryFavorID()
    {
        List<Integer> result = new LinkedList<>();
        result = historyMapper.selectHistoryIDByNameAndIsFavor(LoginInUser.getName());

        return result;
    }


    public List<History> sendHistory(@RequestParam(required = false) List<History> history)
    {
        List<Integer> IDList = getUsersHistoryID();
        history = new ArrayList<History>();
//        System.out.println(IDList);
        for (Integer i = 0; i < IDList.size(); i++) {
//            System.out.println(historyMapper.selectHistoryByID(getUsersHistoryID().get(i)));
            history.add(historyMapper.selectHistoryByIDAndIsDelete(getUsersHistoryID().get(i)));
        }
//        System.out.println(history);
//        history = historyMapper.selectHistoryByID(getUsersHistoryID().get(0));
//        System.out.println("Service里面的   "+history.getOriginText());
        return history;
    }

    public List<History> sendHistoryTrash(@RequestParam(required = false) List<History> history)
    {
        List<Integer> IDList = getUsersHistoryTrashID();
        history = new ArrayList<History>();
        for (Integer i = 0; i < IDList.size(); i++) {
            history.add(historyMapper.selectHistoryByIDAndIsDeleteYet(getUsersHistoryTrashID().get(i)));
        }
        return history;
    }

    public List<History> sendHistoryFavor(@RequestParam(required = false) List<History> history)
    {
        List<Integer> IDList = getUsersHistoryFavorID();
        history = new ArrayList<History>();
        for (Integer i = 0; i < IDList.size(); i++) {
            history.add(historyMapper.selectHistoryByIDAndIsFavor(getUsersHistoryFavorID().get(i)));
        }
        return history;
    }
}

